$(document).ready(function(e) {

    // var state = false;
    // $("#email").focus(function () {
    //     if (state == false) {
    //         $(this).val('');
    //     }
    // })
    $("#next").click(function (e) {
        var email = $("#email").val();
        var password = $("#password").val();
        var againPassword = $("#againPassword").val();
        var p = /[0-9]/; var number = p.test(password);
        var l = /[a-z]/i; var letter = l.test(password);
        var len = password.trim().length;
        if (email == "") {
            alert("邮箱不能为空");
            return;
        }

        if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email) == false) {
            alert("邮箱格式不正确，请重新输入");
            return;
        }

        if (password == ""||againPassword=="") {
            alert("密码不能为空");
            return;
        }
        if(password!=againPassword){
            alert("兩次密碼輸入密码不同");
            return;
        }
        if(len<6){
            alert("密码必须大于6位数");
            return;
        }
        if(number==false){
            alert("密码中必须包含数字");
            return;
        }
        if(letter==false){
            alert("密码中必须包含字母");
            return;
        }
        // var ischeck=$("#checkboxId").is(':checked');
        // if(ischeck){
        //     deleteInfo();
        //     saveInfo(phoneNo,password);
        // }
        $("#next").css("background", "#ccc");
        $("#next").attr("disabled", true);
        var registerEntity= {};
        registerEntity['userEmail']=email;
        registerEntity['password']=password;
        $.ajax({
            url: 'register.do',
            method: 'post',
            contentType: 'application/json', // 这句不加出现415错误:Unsupported Media Type
            data: JSON.stringify(registerEntity), // 以json字符串方式传递
            success: function(data) {
                if(data=="email is exist"){
                    alert(data);
                }else{
                    url="login";
                    window.location.href=url;
                }
                $("#next").attr("disabled", false)
            },
            error: function(data) {
                console.log("error...");
                $("#next").attr("disabled", false)
            }
        });
    })
})
